home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / prog / gnu-c / src / gcc-2.7.0-amiga / fixincludes < prev    next >
Text File  |  1995-08-24  |  88KB  |  2,480 lines

  1. #! /bin/sh
  2. # Install modified versions of certain ANSI-incompatible system header files
  3. # which are fixed to work correctly with ANSI C
  4. # and placed in a directory that GNU C will search.
  5.  
  6. # See README-fixinc for more information.
  7.  
  8. # Directory containing the original header files.
  9. # (This was named INCLUDES, but that conflicts with a name in Makefile.in.)
  10. INPUT=${2-${INPUT-/usr/include}}
  11.  
  12. # Directory in which to store the results.
  13. LIB=${1?"fixincludes: output directory not specified"}
  14.  
  15. # Define PWDCMD as a command to use to get the working dir
  16. # in the form that we want.
  17. PWDCMD=pwd
  18. case "`pwd`" in
  19. //*)
  20.     # On an Apollo, discard everything before `/usr'.
  21.     PWDCMD="eval pwd | sed -e 's,.*/usr/,/usr/,'"
  22.     ;;
  23. esac
  24.  
  25. # Original directory.
  26. ORIGDIR=`${PWDCMD}`
  27.  
  28. # Make sure it exists.
  29. if [ ! -d $LIB ]; then
  30.   mkdir $LIB || exit 1
  31. fi
  32.  
  33. # Make LIB absolute only if needed to avoid problems with the amd.
  34. case $LIB in
  35. /*)
  36.     ;;
  37. *)
  38.     cd $LIB; LIB=`${PWDCMD}`
  39.     ;;
  40. esac
  41.  
  42. # Fail if no arg to specify a directory for the output.
  43. if [ x$1 = x ]
  44. then echo fixincludes: no output directory specified
  45. exit 1
  46. fi
  47.  
  48. echo Building fixed headers in ${LIB}
  49.  
  50. # Determine whether this system has symbolic links.
  51. if ln -s X $LIB/ShouldNotExist 2>/dev/null; then
  52.   rm -f $LIB/ShouldNotExist
  53.   LINKS=true
  54. elif ln -s X /tmp/ShouldNotExist 2>/dev/null; then
  55.   rm -f /tmp/ShouldNotExist
  56.   LINKS=true
  57. else
  58.   LINKS=false
  59. fi
  60. # AmigaDOS hack - we have symbolic links, but it's generally
  61. # better to not depend on them working correctly.
  62. LINKS=false
  63.  
  64. echo Finding directories and links to directories
  65. cd ${INPUT}
  66. # Find all directories and all symlinks that point to directories.
  67. # Put the list in $files.
  68. # Each time we find a symlink, add it to newdirs
  69. # so that we do another find within the dir the link points to.
  70. # Note that $files may have duplicates in it;
  71. # later parts of this file are supposed to ignore them.
  72. dirs="."
  73. levels=2
  74. while [ -n "$dirs" ] && [ $levels -gt 0 ]
  75. do
  76.     levels=`expr $levels - 1`
  77.     newdirs=
  78.     for d in $dirs
  79.     do
  80.     echo " Searching $INPUT/$d"
  81.     if [ "$d" != . ]
  82.     then
  83.         d=$d/.
  84.     fi
  85.  
  86.     # Find all directories under $d, relative to $d, excluding $d itself.
  87.         files="$files `find $d -type d -print | \
  88.                sed -e '/\/\.$/d' -e '/^\.$/d'`"
  89.     # Find all links to directories.
  90.     # Using `-exec test -d' in find fails on some systems,
  91.     # and trying to run test via sh fails on others,
  92.     # so this is the simplest alternative left.
  93.     # First find all the links, then test each one.
  94.     theselinks=
  95.     $LINKS && \
  96.       theselinks=`find $d -type l -print`
  97.     for d1 in $theselinks --dummy--
  98.     do
  99.         # If the link points to a directory,
  100.         # add that dir to $newdirs
  101.         if [ -d $d1 ]
  102.         then
  103.         files="$files $d1"
  104.         if [ "`ls -ld $d1 | sed -n 's/.*-> //p'`" != "." ]
  105.         then
  106.             newdirs="$newdirs $d1"
  107.         fi
  108.         fi
  109.     done
  110.     done
  111.  
  112.     dirs="$newdirs"
  113. done
  114.  
  115. dirs=
  116. echo "All directories (including links to directories):"
  117. echo $files
  118.  
  119. for file in $files; do
  120.   rm -rf $LIB/$file
  121.   if [ ! -d $LIB/$file ]
  122.   then mkdir $LIB/$file
  123.   fi
  124. done
  125. mkdir $LIB/root
  126.  
  127. # treetops gets an alternating list
  128. # of old directories to copy
  129. # and the new directories to copy to.
  130. treetops="${INPUT} ${LIB}"
  131.  
  132. if $LINKS; then
  133.   echo 'Making symbolic directory links'
  134.   for file in $files; do
  135.     dest=`ls -ld $file | sed -n 's/.*-> //p'`
  136.     if [ "$dest" ]; then    
  137.       cwd=`${PWDCMD}`
  138.       # In case $dest is relative, get to $file's dir first.
  139.       cd ${INPUT}
  140.       cd `echo ./$file | sed -n 's&[^/]*$&&p'`
  141.       # Check that the target directory exists.
  142.       # Redirections changed to avoid bug in sh on Ultrix.
  143.       (cd $dest) > /dev/null 2>&1
  144.       if [ $? = 0 ]; then
  145.     cd $dest
  146.     # X gets the dir that the link actually leads to.
  147.     x=`${PWDCMD}`
  148.     # Canonicalize ${INPUT} now to minimize the time an
  149.     # automounter has to change the result of ${PWDCMD}.
  150.     cinput=`cd ${INPUT}; ${PWDCMD}`
  151.     # If a link points to ., make a similar link to .
  152.     if [ $x = ${cinput} ]; then
  153.       echo $file '->' . ': Making link'
  154.       rm -fr ${LIB}/$file > /dev/null 2>&1
  155.       ln -s . ${LIB}/$file > /dev/null 2>&1
  156.     # If link leads back into ${INPUT},
  157.     # make a similar link here.
  158.     elif expr $x : "${cinput}/.*" > /dev/null; then
  159.       # Y gets the actual target dir name, relative to ${INPUT}.
  160.       y=`echo $x | sed -n "s&${cinput}/&&p"`
  161.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  162.       dots=`echo "$file" |
  163.         sed -e 's@^./@@' -e 's@/./@/@g' -e 's@[^/][^/]*@..@g' -e 's@..$@@'`
  164.       echo $file '->' $dots$y ': Making link'
  165.       rm -fr ${LIB}/$file > /dev/null 2>&1
  166.       ln -s $dots$y ${LIB}/$file > /dev/null 2>&1
  167.     else
  168.       # If the link is to a dir $target outside ${INPUT},
  169.       # repoint the link at ${INPUT}/root$target
  170.       # and process $target into ${INPUT}/root$target
  171.       # treat this directory as if it actually contained the files.
  172.       echo $file '->' root$x ': Making link'
  173.       if [ -d $LIB/root$x ]
  174.       then true
  175.       else
  176.         dirname=root$x/
  177.         dirmade=.
  178.         cd $LIB
  179.         while [ x$dirname != x ]; do
  180.           component=`echo $dirname | sed -e 's|/.*$||'`
  181.           mkdir $component >/dev/null 2>&1
  182.           cd $component
  183.           dirmade=$dirmade/$component
  184.           dirname=`echo $dirname | sed -e 's|[^/]*/||'`
  185.         done
  186.       fi
  187.       # Duplicate directory structure created in ${LIB}/$file in new
  188.       # root area.
  189.       for file2 in $files; do
  190.         case $file2 in
  191.           $file/./*)
  192.         dupdir=${LIB}/root$x/`echo $file2 | sed -n "s|^${file}/||p"`
  193.         echo "Duplicating ${file}'s ${dupdir}"
  194.         if [ -d ${dupdir} ]
  195.         then true
  196.         else
  197.           mkdir ${dupdir}
  198.         fi
  199.         ;;
  200.           *)
  201.         ;;
  202.         esac
  203.           done
  204.       # Get the path from ${LIB} to $file, accounting for symlinks.
  205.       parent=`echo "$file" | sed -e 's@/[^/]*$@@'`
  206.       libabs=`cd ${LIB}; ${PWDCMD}`
  207.       file2=`cd ${LIB}; cd $parent; ${PWDCMD} | sed -e "s@^${libabs}@@"`
  208.       # DOTS is the relative path from ${LIB}/$file's dir back to ${LIB}.
  209.       dots=`echo "$file2" | sed -e 's@/[^/]*@../@g'`
  210.       rm -fr ${LIB}/$file > /dev/null 2>&1
  211.       ln -s ${dots}root$x ${LIB}/$file > /dev/null 2>&1
  212.       treetops="$treetops $x ${LIB}/root$x"
  213.     fi
  214.       fi
  215.       cd $cwd
  216.     fi
  217.   done
  218. fi
  219.  
  220. required=
  221. set x $treetops
  222. shift
  223. while [ $# != 0 ]; do
  224.   # $1 is an old directory to copy, and $2 is the new directory to copy to.
  225.   cd ${INPUT}
  226.   cd $1
  227. # The same dir can appear more than once in treetops.
  228. # There's no need to scan it more than once.
  229.   if [ -f $2/DONE ]
  230.   then
  231.     files=
  232.   else
  233.     touch $2/DONE
  234.     echo Fixing directory $1 into $2
  235. # Check .h files which are symlinks as well as those which are files.
  236. # A link to a header file will not be processed by anything but this.
  237.     if $LINKS; then
  238.       files=`find . -name '*.h' \( -type f -o -type l \) -print`
  239.     else
  240.       files=`find . -name '*.h' -type f -print`
  241.     fi
  242.     echo Checking header files
  243.   fi
  244. # Note that BSD43_* are used on recent MIPS systems.
  245.   for file in $files; do
  246. # This call to egrep is essential, since checking a file with egrep
  247. # is much faster than actually trying to fix it.
  248. # It is also essential that most files *not* match!
  249. # Thus, matching every #endif is unacceptable.
  250. # But the argument to egrep must be kept small, or many versions of egrep
  251. # won't be able to handle it.
  252. #
  253. # We use the pattern [!-.0-~] instead of [^/     ] to match a noncomment
  254. # following #else or #endif because some buggy egreps think [^/] matches
  255. # newline, and they thus think `#else ' matches `#e[ndiflse]*[     ]+[^/     ]'.
  256. #
  257. # We use the pattern [^a-zA-Z0-9_][_a-ce-km-z][a-z0-9] to match an identifier
  258. # following #if or #elif that is not surrounded by __.  The `a-ce-km-z'
  259. # in this pattern lacks `d' and `l'; this means we don't worry about
  260. # identifiers starting with `d' or `l'.  This is OK, since none of the
  261. # identifiers below start with `d' or `l'.  It also greatly improves
  262. # performance, since many files contain lines of the form `#if ... defined ...'
  263. # or `#if lint'.
  264.     if egrep '//|[     _]_IO|CTRL|^#define.NULL|^#e[nl][ds][ief]*[     ]+[!-.0-~]|^#[el]*if.*[^a-zA-Z0-9_][_a-ce-km-zA-Z][a-zA-Z0-9]' $file >/dev/null; then
  265.       if [ -r $file ]; then
  266.     cp $file $2/$file >/dev/null 2>&1    \
  267.     || echo "Can't copy $file"
  268.     chmod +w $2/$file
  269.     chmod a+r $2/$file
  270.     # Here is how the sed commands in braces work.
  271.     # (It doesn't work to put the comments inside the sed commands.)
  272.         # Surround each word with spaces, to simplify matching below.
  273.         # ANSIfy each pre-ANSI machine-dependent symbol
  274.         # by surrounding it with __ __.
  275.         # Remove the spaces that we inserted around each word.
  276.     sed -e '
  277.                    :loop
  278.       /\\$/            N
  279.       /\\$/            b loop
  280.       s%^\([     ]*#[     ]*else\)[     ]*/[^*].*%\1%
  281.       s%^\([     ]*#[     ]*else\)[     ]*[^/     ].*%\1%
  282.       s%^\([     ]*#[     ]*endif\)[     ]*/[^*].*%\1%
  283.       s%^\([     ]*#[     ]*endif\)[     ]*\*[^/].*%\1%
  284.       s%^\([     ]*#[     ]*endif\)[     ]*[^/*     ].*%\1%
  285.       /\/\/[^*]/            s|//\(.*\)$|/*\1*/|
  286.       /[     ]_IO[A-Z]*[     ]*(/    s/\(_IO[A-Z]*[     ]*(\)\(.\),/\1'\''\2'\'',/
  287.       /[     ]BSD43__IO[A-Z]*[     ]*(/    s/(\(.\),/('\''\1'\'',/
  288.       /#define._IO/            s/'\''\([cgxtf]\)'\''/\1/g
  289.       /#define.BSD43__IO/        s/'\''\([cgx]\)'\''/\1/g
  290.       /[^A-Z0-9_]CTRL[     ]*(/        s/\([^'\'']\))/'\''\1'\'')/
  291.       /[^A-Z0-9]_CTRL[     ]*(/        s/\([^'\'']\))/'\''\1'\'')/
  292.       /#define[     ]*[     ]CTRL/        s/'\''\([cgx]\)'\''/\1/g
  293.       /#define[     ]*[     ]_CTRL/        s/'\''\([cgx]\)'\''/\1/g
  294.       /#define.BSD43_CTRL/        s/'\''\([cgx]\)'\''/\1/g
  295.       /#[     ]*[el]*if/{
  296.         s/[a-zA-Z0-9_][a-zA-Z0-9_]*/ & /g
  297.  
  298.         s/ bsd4\([0-9]\) / __bsd4\1__ /g
  299.         s/ _*host_mips / __host_mips__ /g
  300.         s/ _*i386 / __i386__ /g
  301.         s/ M32 / __M32__ /g
  302.         s/ is68k / __is68k__ /g
  303.         s/ m68k / __m68k__ /g
  304.         s/ mc680\([0-9]\)0 / __mc680\10__ /g
  305.         s/ m88k / __m88k__ /g
  306.         s/ _*mips / __mips__ /g
  307.         s/ news\([0-9]*\) / __news\1__ /g
  308.         s/ ns32000 / __ns32000__ /g
  309.         s/ pdp11 / __pdp11__ /g
  310.         s/ pyr / __pyr__ /g
  311.         s/ sel / __sel__ /g
  312.         s/ sony_news / __sony_news__ /g
  313.         s/ sparc / __sparc__ /g
  314.         s/ sun\([a-z0-9]*\) / __sun\1__ /g
  315.         s/ tahoe / __tahoe__ /g
  316.         s/ tower\([_0-9]*\) / __tower\1__ /g
  317.         s/ u370 / __u370__ /g
  318.         s/ u3b\([0-9]*\) / __u3b\1__ /g
  319.         s/ unix / __unix__ /g
  320.         s/ vax / __vax__ /g
  321.         s/ _*MIPSE\([LB]\) / __MIPSE\1__ /g
  322.         s/ _*\([Rr][34]\)000 / __\1000__ /g
  323.         s/ _*SYSTYPE_\([A-Z0-9]*\) / __SYSTYPE_\1__ /g
  324.  
  325.         s/ \([a-zA-Z0-9_][a-zA-Z0-9_]*\) /\1/g
  326.       }
  327.       /^#define.NULL[     ]/    i\
  328.         #undef NULL
  329.     ' $2/$file > $2/$file.
  330.     mv $2/$file. $2/$file
  331.     if cmp $file $2/$file >/dev/null 2>&1 \
  332.         || egrep 'This file is part of the GNU C Library' $2/$file >/dev/null 2>&1; then
  333.        rm $2/$file
  334.     else
  335.        echo Fixed $file
  336.        # Find any include directives that use "file".
  337.        for include in `egrep '^[     ]*#[     ]*include[     ]*"[^/]' $2/$file | sed -e 's/^[     ]*#[     ]*include[     ]*"\([^"]*\)".*$/\1/'`; do
  338.           dir=`echo $file | sed -e s'|/[^/]*$||'`
  339.           required="$required $1 $dir/$include $2/$dir/$include"
  340.        done
  341.     fi
  342.       fi
  343.     fi
  344.   done
  345.   shift; shift
  346. done
  347.  
  348. cd ${INPUT}
  349.  
  350. # Install the proper definition of the three standard types in header files
  351. # that they come from.
  352. for file in sys/types.h stdlib.h sys/stdtypes.h stddef.h memory.h unistd.h; do
  353.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  354.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  355.     chmod +w ${LIB}/$file 2>/dev/null
  356.     chmod a+r ${LIB}/$file 2>/dev/null
  357.   fi
  358.  
  359.   if [ -r ${LIB}/$file ]; then
  360.     echo Fixing size_t, ptrdiff_t and wchar_t in $file
  361.     sed \
  362.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/i\
  363. #ifndef __SIZE_TYPE__\
  364. #define __SIZE_TYPE__ long unsigned int\
  365. #endif
  366. ' \
  367.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]size_t/typedef __SIZE_TYPE__ size_t/' \
  368.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/i\
  369. #ifndef __PTRDIFF_TYPE__\
  370. #define __PTRDIFF_TYPE__ long int\
  371. #endif
  372. ' \
  373.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]ptrdiff_t/typedef __PTRDIFF_TYPE__ ptrdiff_t/' \
  374.       -e '/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/i\
  375. #ifndef __WCHAR_TYPE__\
  376. #define __WCHAR_TYPE__ int\
  377. #endif
  378. ' \
  379.       -e 's/typedef[     ][     ]*[a-z_][     a-z_]*[     ]wchar_t/typedef __WCHAR_TYPE__ wchar_t/' \
  380.       ${LIB}/$file > ${LIB}/${file}.sed
  381.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  382.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  383.       rm ${LIB}/$file
  384.     else
  385.       # Find any include directives that use "file".
  386.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  387.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  388.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  389.       done
  390.     fi
  391.   fi
  392. done
  393.  
  394. # Fix one other error in this file: a mismatched quote not inside a C comment.
  395. file=sundev/vuid_event.h
  396. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  397.   mkdir ${LIB}/sundev 2>/dev/null
  398.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  399.   chmod +w ${LIB}/$file 2>/dev/null
  400.   chmod a+r ${LIB}/$file 2>/dev/null
  401. fi
  402.  
  403. if [ -r ${LIB}/$file ]; then
  404.   echo Fixing $file comment
  405.   sed -e "s/doesn't/does not/" ${LIB}/$file > ${LIB}/${file}.sed
  406.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  407.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  408.     rm ${LIB}/$file
  409.   else
  410.     # Find any include directives that use "file".
  411.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  412.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  413.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  414.     done
  415.   fi
  416. fi
  417.  
  418. # Fix these Sun OS files to avoid an invalid identifier in an #ifdef.
  419. file=sunwindow/win_cursor.h
  420. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  421. #  mkdir ${LIB}/sunwindow 2>/dev/null
  422.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  423.   chmod +w ${LIB}/$file 2>/dev/null
  424. fi
  425. if [ -r ${LIB}/$file ]; then
  426.   echo Fixing $file
  427.   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
  428.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  429.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  430.     rm ${LIB}/$file
  431.   else
  432.     # Find any include directives that use "file".
  433.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  434.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  435.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  436.     done
  437.   fi
  438. fi
  439. file=sunwindow/win_lock.h
  440. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  441. #  mkdir ${LIB}/sunwindow 2>/dev/null
  442.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  443.   chmod +w ${LIB}/$file 2>/dev/null
  444. fi
  445. if [ -r ${LIB}/$file ]; then
  446.   echo Fixing $file
  447.   sed -e "s/ecd.cursor/ecd_cursor/" ${LIB}/$file > ${LIB}/${file}.sed
  448.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  449.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  450.     rm ${LIB}/$file
  451.   else
  452.     # Find any include directives that use "file".
  453.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  454.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  455.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  456.     done
  457.   fi
  458. fi
  459.  
  460. # Fix this Sun file to avoid interfering with stddef.h.
  461. file=sys/stdtypes.h
  462. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  463.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  464.   chmod +w ${LIB}/$file 2>/dev/null
  465.   chmod a+r ${LIB}/$file 2>/dev/null
  466. fi
  467.  
  468. if [ -r ${LIB}/$file ]; then
  469.   echo Fixing $file
  470. sed -e '/[     ]size_t.*;/i\
  471. #ifndef _GCC_SIZE_T\
  472. #define _GCC_SIZE_T
  473. ' \
  474.     -e '/[     ]size_t.*;/a\
  475. #endif
  476. ' \
  477.     -e '/[     ]ptrdiff_t.*;/i\
  478. #ifndef _GCC_PTRDIFF_T\
  479. #define _GCC_PTRDIFF_T
  480. ' \
  481.     -e '/[     ]ptrdiff_t.*;/a\
  482. #endif
  483. ' \
  484.     -e '/[     ]wchar_t.*;/i\
  485. #ifndef _GCC_WCHAR_T\
  486. #define _GCC_WCHAR_T
  487. ' \
  488.     -e '/[     ]wchar_t.*;/a\
  489. #endif
  490. ' ${LIB}/$file > ${LIB}/${file}.sed
  491.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  492.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  493.     rm ${LIB}/$file
  494.   else
  495.     # Find any include directives that use "file".
  496.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  497.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  498.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  499.     done
  500.   fi
  501. fi
  502.  
  503. # Fix this ARM/RISCiX file to avoid interfering with the use of __wchar_t
  504. # in cc1plus.
  505. file=stdlib.h
  506. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  507.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  508.   chmod +w ${LIB}/$file 2>/dev/null
  509.   chmod a+r ${LIB}/$file 2>/dev/null
  510. fi
  511.  
  512. if [ -r ${LIB}/$file ]; then
  513.   echo Fixing $file
  514.   sed -e "s/\(#[     ]*ifndef[     ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
  515.       -e "s/\(#[     ]*define[     ]*\)__wchar_t/\1_GCC_WCHAR_T/" \
  516.      ${LIB}/$file > ${LIB}/${file}.sed
  517.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  518.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  519.     rm ${LIB}/$file
  520.   else
  521.     # Find any include directives that use "file".
  522.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  523.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  524.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  525.     done
  526.   fi
  527. fi
  528.  
  529. # Fix this ARM/RISCiX file where ___type is a Compiler hint that is specific to
  530. # the Norcroft compiler.
  531. file=X11/Intrinsic.h
  532. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  533.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  534.   chmod +w ${LIB}/$file 2>/dev/null
  535.   chmod a+r ${LIB}/$file 2>/dev/null
  536. fi
  537.  
  538. if [ -r ${LIB}/$file ]; then
  539.   echo Fixing $file
  540.   sed -e "s/___type p_type/p_type/" \
  541.      ${LIB}/$file > ${LIB}/${file}.sed
  542.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  543.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  544.     rm ${LIB}/$file
  545.   else
  546.     # Find any include directives that use "file".
  547.     for include in `egrep '^[         ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  548.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  549.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  550.     done
  551.   fi
  552. fi
  553.  
  554. # Fix this file to avoid interfering with stddef.h, but don't mistakenly
  555. # match ssize_t present in AIX for the ps/2, or typedefs which use (but do not
  556. # set) size_t.
  557. file=sys/types.h
  558. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  559.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  560.   chmod +w ${LIB}/$file 2>/dev/null
  561.   chmod a+r ${LIB}/$file 2>/dev/null
  562. fi
  563.  
  564. if [ -r ${LIB}/$file ]; then
  565.   echo Fixing $file
  566. sed -e '/typedef[     ][     ]*[A-Za-z_][     A-Za-z_]*[     ]size_t/i\
  567. #ifndef _GCC_SIZE_T\
  568. #define _GCC_SIZE_T
  569. ' \
  570.     -e '/typedef[     ][     ]*[A-Za-z_][     A-Za-z_]*[     ]size_t/a\
  571. #endif
  572. ' ${LIB}/$file > ${LIB}/${file}.sed
  573.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  574.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  575.     rm ${LIB}/$file
  576.   else
  577.     # Find any include directives that use "file".
  578.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  579.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  580.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  581.     done
  582.   fi
  583. fi
  584.  
  585. # Fix HP's use of ../machine/inline.h to refer to
  586. # /usr/include/machine/inline.h
  587. file=sys/spinlock.h
  588. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  589.   cp $file ${LIB}/$file
  590. fi
  591. if [ -r ${LIB}/$file ] ; then
  592.   echo Fixing $file
  593.   sed -e 's,"../machine/inline.h",<machine/inline.h>,' \
  594.     -e 's,"../machine/psl.h",<machine/psl.h>,' \
  595.   ${LIB}/$file > ${LIB}/${file}.sed
  596.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  597.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  598.     rm ${LIB}/$file
  599.   else
  600.     # Find any include directives that use "file".
  601.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  602.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  603.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  604.     done
  605.   fi
  606. fi
  607.  
  608. # Fix an error in this file: the #if says _cplusplus, not the double
  609. # underscore __cplusplus that it should be
  610. file=tinfo.h
  611. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  612.   mkdir ${LIB}/rpcsvc 2>/dev/null
  613.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  614.   chmod +w ${LIB}/$file 2>/dev/null
  615.   chmod a+r ${LIB}/$file 2>/dev/null
  616. fi
  617.  
  618. if [ -r ${LIB}/$file ]; then
  619.   echo Fixing $file, __cplusplus macro
  620.   sed -e 's/[     ]_cplusplus/ __cplusplus/' ${LIB}/$file > ${LIB}/${file}.sed
  621.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  622.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  623.     rm ${LIB}/$file
  624.   else
  625.     # Find any include directives that use "file".
  626.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  627.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  628.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  629.     done
  630.   fi
  631. fi
  632.  
  633. # Fix an error in this file: a missing semi-colon at the end of the statsswtch
  634. # structure definition.
  635. file=rpcsvc/rstat.h
  636. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  637.   mkdir ${LIB}/rpcsvc 2>/dev/null
  638.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  639.   chmod +w ${LIB}/$file 2>/dev/null
  640.   chmod a+r ${LIB}/$file 2>/dev/null
  641. fi
  642.  
  643. if [ -r ${LIB}/$file ]; then
  644.   echo Fixing $file, definition of statsswtch
  645.   sed -e 's/boottime$/boottime;/' ${LIB}/$file > ${LIB}/${file}.sed
  646.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  647.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  648.     rm ${LIB}/$file
  649.   else
  650.     # Find any include directives that use "file".
  651.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  652.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  653.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  654.     done
  655.   fi
  656. fi
  657.  
  658. # Fix an error in this file: a missing semi-colon at the end of the nodeent
  659. # structure definition.
  660. file=netdnet/dnetdb.h
  661. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  662.   mkdir ${LIB}/netdnet 2>/dev/null
  663.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  664.   chmod +w ${LIB}/$file 2>/dev/null
  665.   chmod a+r ${LIB}/$file 2>/dev/null
  666. fi
  667.  
  668. if [ -r ${LIB}/$file ]; then
  669.   echo Fixing $file, definition of nodeent
  670.   sed -e 's/char.*na_addr *$/char *na_addr;/' ${LIB}/$file > ${LIB}/${file}.sed
  671.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  672.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  673.     rm ${LIB}/$file
  674.   else
  675.     # Find any include directives that use "file".
  676.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  677.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  678.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  679.     done
  680.   fi
  681. fi
  682.  
  683. # Check for bad #ifdef line (in Ultrix 4.1)
  684. file=sys/file.h
  685. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  686.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  687.   chmod +w ${LIB}/$file 2>/dev/null
  688.   chmod a+r ${LIB}/$file 2>/dev/null
  689. fi
  690.  
  691. if [ -r ${LIB}/$file ]; then
  692.   echo Fixing $file, bad \#ifdef line
  693.   sed -e 's/#ifdef KERNEL/#if defined(KERNEL)/' ${LIB}/$file > ${LIB}/${file}.sed
  694.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  695.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  696.     rm ${LIB}/$file
  697.   else
  698.     # Find any include directives that use "file".
  699.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  700.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  701.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  702.     done
  703.   fi
  704. fi
  705.  
  706. # Check for superfluous `static' (in Ultrix 4.2)
  707. # On Ultrix 4.3, includes of other files (r3_cpu.h,r4_cpu.h) is broken.
  708. file=machine/cpu.h
  709. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  710.   mkdir ${LIB}/machine 2>/dev/null
  711.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  712.   chmod +w ${LIB}/$file 2>/dev/null
  713.   chmod a+r ${LIB}/$file 2>/dev/null
  714. fi
  715.  
  716. if [ -r ${LIB}/$file ]; then
  717.   echo Fixing $file, superfluous static and broken includes of other files.
  718.   sed -e 's/^static struct tlb_pid_state/struct tlb_pid_state/' \
  719.       -e 's/^#include "r3_cpu\.h"$/#include <machine\/r3_cpu\.h>/' \
  720.       -e 's/^#include "r4_cpu\.h"$/#include <machine\/r4_cpu\.h>/' \
  721.       ${LIB}/$file > ${LIB}/${file}.sed
  722.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  723.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  724.     rm ${LIB}/$file
  725.   else
  726.     # Find any include directives that use "file".
  727.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  728.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  729.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  730.     done
  731. # This file has an alternative name, mips/cpu.h.  Fix that name, too.
  732.     if cmp machine/cpu.h mips/cpu.h > /dev/null 2>&1; then
  733.       mkdir ${LIB}/mips 2>&-
  734. # Don't remove the file first, they may be the same file!
  735.       ln ${LIB}/$file ${LIB}/mips/cpu.h > /dev/null 2>&1
  736.     fi
  737.   fi
  738. fi
  739.  
  740. # Incorrect sprintf declaration in X11/Xmu.h
  741. file=X11/Xmu.h
  742. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  743.   mkdir ${LIB}/X11 2>/dev/null
  744.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  745.   chmod +w ${LIB}/$file 2>/dev/null
  746.   chmod a+r ${LIB}/$file 2>/dev/null
  747. fi
  748.  
  749. if [ -r ${LIB}/$file ]; then
  750.   echo Fixing $file sprintf declaration
  751.   sed -e 's,^extern char \*    sprintf();$,#ifndef __STDC__\
  752. extern char *    sprintf();\
  753. #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
  754.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  755.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  756.     rm ${LIB}/$file
  757.   else
  758.     # Find any include directives that use "file".
  759.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  760.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  761.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  762.     done
  763.   fi
  764. fi
  765.  
  766. # Incorrect sprintf declaration in X11/Xmu/Xmu.h
  767. # (It's not clear whether the right file name is this or X11/Xmu.h.)
  768. file=X11/Xmu/Xmu.h
  769. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  770.   mkdir ${LIB}/X11/Xmu 2>/dev/null
  771.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  772.   chmod +w ${LIB}/$file 2>/dev/null
  773.   chmod a+r ${LIB}/$file 2>/dev/null
  774. fi
  775.  
  776. if [ -r ${LIB}/$file ]; then
  777.   echo Fixing $file sprintf declaration
  778.   sed -e 's,^extern char \*    sprintf();$,#ifndef __STDC__\
  779. extern char *    sprintf();\
  780. #endif /* !defined __STDC__ */,' ${LIB}/$file > ${LIB}/${file}.sed
  781.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  782.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  783.     rm ${LIB}/$file
  784.   else
  785.     # Find any include directives that use "file".
  786.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  787.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  788.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  789.     done
  790.   fi
  791. fi
  792.  
  793. # Check for missing ';' in struct
  794. file=netinet/ip.h
  795. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  796.   mkdir ${LIB}/netinet 2>/dev/null
  797.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  798.   chmod +w ${LIB}/$file 2>/dev/null
  799.   chmod a+r ${LIB}/$file 2>/dev/null
  800. fi
  801.  
  802. if [ -r ${LIB}/$file ]; then
  803.   echo Fixing $file
  804.   sed -e '/^struct/,/^};/s/}$/};/' ${LIB}/$file > ${LIB}/${file}.sed
  805.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  806.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  807.     rm -f ${LIB}/$file
  808.   else
  809.     # Find any include directives that use "file".
  810.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  811.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  812.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  813.     done
  814.   fi
  815. fi
  816.  
  817. # Fix the CAT macro in SunOS memvar.h.
  818. file=pixrect/memvar.h
  819. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  820.   mkdir ${LIB}/pixrect 2>/dev/null
  821.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  822.   chmod +w ${LIB}/$file 2>/dev/null
  823.   chmod a+r ${LIB}/$file 2>/dev/null
  824. fi
  825.  
  826. if [ -r ${LIB}/$file ]; then
  827.   echo Fixing $file
  828.   sed -e '/^#define.CAT(a,b)/ i\
  829. #ifdef __STDC__ \
  830. #define CAT(a,b) a##b\
  831. #else
  832. /^#define.CAT(a,b)/ a\
  833. #endif
  834. ' ${LIB}/$file > ${LIB}/${file}.sed
  835.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  836.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  837.     rm -f ${LIB}/$file
  838.   else
  839.     # Find any include directives that use "file".
  840.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  841.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  842.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  843.     done
  844.   fi
  845. fi
  846.  
  847. # Check for yet more missing ';' in struct (in SunOS 4.0.x)
  848. file=rpcsvc/rusers.h
  849. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  850.   mkdir ${LIB}/rpcsvc 2>/dev/null
  851.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  852.   chmod +w ${LIB}/$file 2>/dev/null
  853.   chmod a+r ${LIB}/$file 2>/dev/null
  854. fi
  855.  
  856. if [ -r ${LIB}/$file ]; then
  857.   echo Fixing $file
  858.   sed -e '/^struct/,/^};/s/_cnt$/_cnt;/' ${LIB}/$file > ${LIB}/${file}.sed
  859.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  860.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  861.     rm -f ${LIB}/$file
  862.   else
  863.     # Find any include directives that use "file".
  864.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  865.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  866.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  867.     done
  868.   fi
  869. fi
  870.  
  871. # Fix return type of exit and abort in <stdlib.h> on SunOS 4.1.
  872. # Also wrap protection around size_t for m88k-sysv3 systems.
  873. file=stdlib.h
  874. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  875.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  876.   chmod +w ${LIB}/$file 2>/dev/null
  877.   chmod a+r ${LIB}/$file 2>/dev/null
  878. fi
  879.  
  880. if [ -r ${LIB}/$file ]; then
  881.   echo Fixing $file
  882.   sed -e 's/int    abort/void    abort/g' \
  883.   -e 's/int    free/void    free/g' \
  884.   -e 's/char \*    calloc/void \*    calloc/g' \
  885.   -e 's/char \*    malloc/void \*    malloc/g' \
  886.   -e 's/char \*    realloc/void \*    realloc/g' \
  887.   -e 's/int    exit/void    exit/g' \
  888.   -e '/typedef[     a-zA-Z_]*[     ]size_t[     ]*;/i\
  889. #ifndef _GCC_SIZE_T\
  890. #define _GCC_SIZE_T
  891. ' \
  892.   -e '/typedef[     a-zA-Z_]*[     ]size_t[     ]*;/a\
  893. #endif
  894. ' \
  895.       ${LIB}/$file > ${LIB}/${file}.sed
  896.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  897.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  898.     rm -f ${LIB}/$file
  899.   else
  900.     # Find any include directives that use "file".
  901.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  902.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  903.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  904.     done
  905.   fi
  906. fi
  907.  
  908. # Fix return type of free and {c,m,re}alloc in <malloc.h> on SunOS 4.1.
  909. file=malloc.h
  910. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  911.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  912.   chmod +w ${LIB}/$file 2>/dev/null
  913.   chmod a+r ${LIB}/$file 2>/dev/null
  914. fi
  915.  
  916. if [ -r ${LIB}/$file ]; then
  917.   echo Fixing $file
  918.   sed -e 's/typedef[     ]char \*    malloc_t/typedef void \*    malloc_t/g' \
  919.   -e 's/int[     ][     ]*free/void    free/g' \
  920.   ${LIB}/$file > ${LIB}/${file}.sed
  921.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  922.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  923.     rm -f ${LIB}/$file
  924.   else
  925.     # Find any include directives that use "file".
  926.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  927.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  928.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  929.     done
  930.   fi
  931. fi
  932.  
  933. # Fix bogus #ifdef in <hsfs/hsfs_spec.h> on SunOS 4.1.
  934. file=hsfs/hsfs_spec.h
  935. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  936.   mkdir ${LIB}/hsfs 2>/dev/null
  937.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  938.   chmod +w ${LIB}/$file 2>/dev/null
  939.   chmod a+r ${LIB}/$file 2>/dev/null
  940. fi
  941.  
  942. if [ -r ${LIB}/$file ]; then
  943.   echo Fixing $file
  944.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  945.     ${LIB}/$file > ${LIB}/${file}.
  946.   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
  947.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  948.     rm -f ${LIB}/$file
  949.   else
  950.     # Find any include directives that use "file".
  951.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  952.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  953.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  954.     done
  955.   fi
  956. fi
  957.  
  958. # Fix bogus #ifdef in <hsfs/hsnode.h> on SunOS 4.1.
  959. file=hsfs/hsnode.h
  960. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  961.   mkdir ${LIB}/hsfs 2>/dev/null
  962.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  963.   chmod +w ${LIB}/$file 2>/dev/null
  964.   chmod a+r ${LIB}/$file 2>/dev/null
  965. fi
  966.  
  967. if [ -r ${LIB}/$file ]; then
  968.   echo Fixing $file
  969.   sed -e 's/\#ifdef __i386__ || __sun4c__/\#if __i386__ || __sun4c__/g' \
  970.     ${LIB}/$file > ${LIB}/${file}.sed
  971.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  972.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  973.     rm -f ${LIB}/$file
  974.   else
  975.     # Find any include directives that use "file".
  976.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  977.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  978.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  979.     done
  980.   fi
  981. fi
  982.  
  983. # Fix bogus #ifdef in <hsfs/iso_spec.h> on SunOS 4.1.
  984. file=hsfs/iso_spec.h
  985. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  986.   mkdir ${LIB}/hsfs 2>/dev/null
  987.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  988.   chmod +w ${LIB}/$file 2>/dev/null
  989.   chmod a+r ${LIB}/$file 2>/dev/null
  990. fi
  991.  
  992. if [ -r ${LIB}/$file ]; then
  993.   echo Fixing $file
  994.   sed -e 's/\#ifdef __i386__ || __vax__/\#if __i386__ || __vax__/g' \
  995.     ${LIB}/$file > ${LIB}/${file}.sed
  996.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  997.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  998.     rm -f ${LIB}/$file
  999.   else
  1000.     # Find any include directives that use "file".
  1001.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1002.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1003.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1004.     done
  1005.   fi
  1006. fi
  1007.  
  1008. # Incorrect #include in Sony News-OS 3.2.
  1009. file=machine/machparam.h
  1010. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1011.   mkdir ${LIB}/machine 2>/dev/null
  1012.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1013.   chmod +w ${LIB}/$file 2>/dev/null
  1014.   chmod a+r ${LIB}/$file 2>/dev/null
  1015. fi
  1016.  
  1017. if [ -r ${LIB}/$file ]; then
  1018.   echo Fixing $file, incorrect \#include
  1019.   sed -e 's@"../machine/endian.h"@<machine/endian.h>@' \
  1020.     ${LIB}/$file > ${LIB}/${file}.
  1021.   rm -f ${LIB}/$file; mv ${LIB}/${file}. ${LIB}/$file
  1022.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1023.     rm -f ${LIB}/$file
  1024.   else
  1025.     # Find any include directives that use "file".
  1026.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1027.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1028.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1029.     done
  1030.   fi
  1031. fi
  1032.  
  1033. # Multiline comment after typedef on IRIX 4.0.1.
  1034. file=sys/types.h
  1035. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1036.   mkdir ${LIB}/sys 2>/dev/null
  1037.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1038.   chmod +w ${LIB}/$file 2>/dev/null
  1039.   chmod a+r ${LIB}/$file 2>/dev/null
  1040. fi
  1041.  
  1042. if [ -r ${LIB}/$file ]; then
  1043.   echo Fixing $file, comment in the middle of \#ifdef
  1044.   sed -e 's@type of the result@type of the result */@' \
  1045.     -e 's@of the sizeof@/* of the sizeof@' \
  1046.     ${LIB}/$file > ${LIB}/${file}.sed
  1047.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1048.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1049.     rm -f ${LIB}/$file
  1050.   else
  1051.     # Find any include directives that use "file".
  1052.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1053.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1054.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1055.     done
  1056.   fi
  1057. fi
  1058.  
  1059. # Turning // comments into /* */ comments trashes this IRIX 4.0.1
  1060. # header file, which embeds // comments inside multi-line /* */
  1061. # comments.  If this looks like the IRIX header file, we refix it by
  1062. # just throwing away the // comments.
  1063. file=fam.h
  1064. if [ -r ${LIB}/$file ]; then
  1065.   if egrep indigo.esd ${LIB}/$file > /dev/null; then
  1066.     echo Fixing $file, overeager sed script
  1067.     rm ${LIB}/$file
  1068.     sed -e 's|//.*$||g' $file > ${LIB}/$file
  1069.     chmod +w ${LIB}/$file 2>/dev/null
  1070.     chmod a+r ${LIB}/$file 2>/dev/null
  1071.   fi
  1072. fi
  1073.  
  1074. # Some IRIX header files contains the string "//"
  1075. for file in elf_abi.h elf.h; do
  1076.   if [ -r ${LIB}/$file ]; then
  1077.     echo Fixing $file, overeager sed script
  1078.     sed -e 's|"/\*"\*/|"//"|' ${LIB}/$file > ${LIB}/${file}.sed
  1079.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1080.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1081.       rm -f ${LIB}/$file
  1082.   else
  1083.     # Find any include directives that use "file".
  1084.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1085.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1086.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1087.     done
  1088.     fi
  1089.   fi
  1090. done
  1091.  
  1092. # IRIX 4.0.5 <rpc/auth.h> uses struct sockaddr in prototype without
  1093. # previous definition.
  1094. file=rpc/auth.h
  1095. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1096.   mkdir ${LIB}/rpc 2>/dev/null
  1097.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1098.   chmod +w ${LIB}/$file 2>/dev/null
  1099.   chmod a+r ${LIB}/$file 2>/dev/null
  1100. fi
  1101.  
  1102. if [ -r ${LIB}/$file ]; then
  1103.   echo Fixing $file, undefined type
  1104.   sed -e '/authdes_create.*struct sockaddr/i\
  1105. struct sockaddr;
  1106. ' \
  1107.     ${LIB}/$file > ${LIB}/$file.sed
  1108.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1109.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1110.     rm -f ${LIB}/$file
  1111.   else
  1112.     # Find any include directives that use "file".
  1113.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1114.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1115.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1116.     done
  1117.   fi
  1118. fi
  1119.  
  1120. # IRIX 4.0.5 <rpc/xdr.h> uses struct __file_s in prototype without previous
  1121. # definition.
  1122. file=rpc/xdr.h
  1123. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1124.   mkdir ${LIB}/rpc 2>/dev/null
  1125.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1126.   chmod +w ${LIB}/$file 2>/dev/null
  1127.   chmod a+r ${LIB}/$file 2>/dev/null
  1128. fi
  1129.  
  1130. if [ -r ${LIB}/$file ]; then
  1131.   echo Fixing $file, undefined type
  1132.   sed -e '/xdrstdio_create.*struct __file_s/i\
  1133. struct __file_s;
  1134. ' \
  1135.     ${LIB}/$file > ${LIB}/$file.sed
  1136.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1137.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1138.     rm -f ${LIB}/$file
  1139.   else
  1140.     # Find any include directives that use "file".
  1141.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1142.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1143.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1144.     done
  1145.   fi
  1146. fi
  1147.  
  1148. # Same problem with a file from SunOS 4.1.3 : a header file containing
  1149. # the string "//" embedded in "/**/"
  1150. file=sbusdev/audiovar.h
  1151. if [ -r ${LIB}/$file ]; then
  1152.   echo Fixing $file, overeager sed script
  1153.   rm ${LIB}/$file
  1154.   sed -e 's|//.*$||g' $file > ${LIB}/$file
  1155.   chmod +w ${LIB}/$file 2>/dev/null
  1156.   chmod a+r ${LIB}/$file 2>/dev/null
  1157. fi
  1158.  
  1159. # Fix non-ANSI memcpy declaration that conflicts with gcc's builtin
  1160. # declaration on Sun OS 4.x.  We must only fix this on Sun OS 4.x, because
  1161. # many other systems have similar text but correct versions of the file.
  1162. # To ensure only Sun's is fixed, we grep for a likely unique string.
  1163. file=memory.h
  1164. if [ -r $file ] && egrep '/\*    @\(#\)memory\.h 1\.[2-4] 8./../.. SMI; from S5R2 1\.2    \*/' $file > /dev/null; then
  1165.   if [ ! -r ${LIB}/$file ]; then
  1166.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1167.     chmod +w ${LIB}/$file 2>/dev/null
  1168.     chmod a+r ${LIB}/$file 2>/dev/null
  1169.   fi
  1170.   if [ -r ${LIB}/$file ]; then
  1171.     echo Replacing $file
  1172.     cat > ${LIB}/$file << EOF
  1173. /* This file was generated by fixincludes */
  1174. #ifndef __memory_h__
  1175. #define __memory_h__
  1176.  
  1177. #ifdef __STDC__
  1178. extern void *memccpy();
  1179. extern void *memchr();
  1180. extern void *memcpy();
  1181. extern void *memset();
  1182. #else
  1183. extern char *memccpy();
  1184. extern char *memchr();
  1185. extern char *memcpy();
  1186. extern char *memset();
  1187. #endif /* __STDC__ */
  1188.  
  1189. extern int memcmp();
  1190.  
  1191. #endif /* __memory_h__ */
  1192. EOF
  1193.   fi
  1194. fi
  1195.  
  1196. # parameters not const on DECstation Ultrix V4.0 and OSF/1.
  1197. file=stdio.h
  1198. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1199.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1200.   chmod +w ${LIB}/$file 2>/dev/null
  1201.   chmod a+r ${LIB}/$file 2>/dev/null
  1202. fi
  1203.  
  1204. if [ -r ${LIB}/$file ]; then
  1205.   echo Fixing $file, non-const arg
  1206.   sed -e 's@perror( char \*__s );@perror( const char *__s );@' \
  1207.       -e 's@fputs( char \*__s,@fputs( const char *__s,@' \
  1208.       -e 's@fopen( char \*__filename, char \*__type );@fopen( const char *__filename, const char *__type );@' \
  1209.       -e 's@fwrite( void \*__ptr,@fwrite( const void *__ptr,@' \
  1210.       -e 's@fscanf( FILE \*__stream, char \*__format,@fscanf( FILE *__stream, const char *__format,@' \
  1211.       -e 's@scanf( char \*__format,@scanf( const char *__format,@' \
  1212.       -e 's@sscanf( char \*__s, char \*__format,@sscanf( const char *__s, const char *__format,@' \
  1213.       -e 's@popen(char \*, char \*);@popen(const char *, const char *);@' \
  1214.       -e 's@tempnam(char\*,char\*);@tempnam(const char*,const char*);@' \
  1215.     ${LIB}/$file > ${LIB}/${file}.sed
  1216.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1217.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1218.     rm -f ${LIB}/$file
  1219.   else
  1220.     # Find any include directives that use "file".
  1221.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1222.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1223.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1224.     done
  1225.   fi
  1226. fi
  1227.  
  1228. # parameters conflict with C++ new on rs/6000 
  1229. for file in stdio.h unistd.h ; do
  1230.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1231.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1232.     chmod +w ${LIB}/$file 2>/dev/null
  1233.   fi
  1234.  
  1235.   if [ -r ${LIB}/$file ]; then
  1236.     echo Fixing $file, parameter name conflicts
  1237.     sed -e 's@rename(const char \*old, const char \*new)@rename(const char *_old, const char *_new)@' \
  1238.       ${LIB}/$file > ${LIB}/${file}.sed
  1239.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1240.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1241.       rm -f ${LIB}/$file
  1242.     else
  1243.       # Find any include directives that use "file".
  1244.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1245.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  1246.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1247.       done
  1248.     fi
  1249.   fi
  1250. done
  1251.  
  1252. # function class(double x) conflicts with C++ keyword on rs/6000 
  1253. file=math.h
  1254. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1255.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1256.   chmod +w ${LIB}/$file 2>/dev/null
  1257.   chmod a+r ${LIB}/$file 2>/dev/null
  1258. fi
  1259.  
  1260. if [ -r ${LIB}/$file ]; then
  1261.   if grep 'class[(]' ${LIB}/$file >/dev/null; then
  1262.     echo Fixing $file
  1263.     sed -e '/class[(]/i\
  1264. #ifndef __cplusplus
  1265. ' \
  1266.         -e '/class[(]/a\
  1267. #endif
  1268. ' ${LIB}/$file > ${LIB}/${file}.sed
  1269.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1270.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1271.       rm ${LIB}/$file
  1272.     else
  1273.       # Find any include directives that use "file".
  1274.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1275.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  1276.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1277.       done
  1278.     fi
  1279.   fi
  1280. fi
  1281.  
  1282. # Wrong fchmod prototype on RS/6000.
  1283. file=sys/stat.h
  1284. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1285.   mkdir ${LIB}/sys 2>/dev/null
  1286.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1287.   chmod +w ${LIB}/$file 2>/dev/null
  1288.   chmod a+r ${LIB}/$file 2>/dev/null
  1289. fi
  1290.  
  1291. if [ -r ${LIB}/$file ]; then
  1292.   echo Fixing $file, fchmod prototype
  1293.   sed -e 's/fchmod(char \*/fchmod(int/' \
  1294.     ${LIB}/$file > ${LIB}/$file.sed
  1295.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1296.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1297.     rm -f ${LIB}/$file
  1298.   else
  1299.     # Find any include directives that use "file".
  1300.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1301.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1302.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1303.     done
  1304.   fi
  1305. fi
  1306.  
  1307. # There are several name conflicts with C++ reserved words in X11
  1308. # header files.  These are fixed in some versions, so don't do the
  1309. # fixes if we find __cplusplus in the file.  These were found on the
  1310. # RS/6000.
  1311.  
  1312. # class in X11/ShellP.h
  1313. file=X11/ShellP.h
  1314. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1315.   mkdir ${LIB}/sys 2>/dev/null
  1316.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1317.   chmod +w ${LIB}/$file 2>/dev/null
  1318.   chmod a+r ${LIB}/$file 2>/dev/null
  1319. fi
  1320.  
  1321. if [ -r ${LIB}/$file ]; then
  1322.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1323.     true;
  1324.   else
  1325.     echo Fixing $file, field class
  1326.     sed -e '/char [*]class;/i\
  1327. #ifdef __cplusplus\
  1328.     char *c_class;\
  1329. #else
  1330. ' \
  1331.         -e '/char [*]class;/a\
  1332. #endif
  1333. ' ${LIB}/$file > ${LIB}/${file}.sed
  1334.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1335.   fi
  1336.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1337.     rm -f ${LIB}/$file
  1338.   else
  1339.     # Find any include directives that use "file".
  1340.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1341.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1342.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1343.     done
  1344.   fi
  1345. fi
  1346. # new in Xm/Traversal.h
  1347. file=Xm/Traversal.h
  1348. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1349.   mkdir ${LIB}/sys 2>/dev/null
  1350.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1351.   chmod +w ${LIB}/$file 2>/dev/null
  1352.   chmod a+r ${LIB}/$file 2>/dev/null
  1353. fi
  1354.  
  1355. if [ -r ${LIB}/$file ]; then
  1356.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1357.     true;
  1358.   else
  1359.     echo Fixing $file, uses of new
  1360.     sed -e '/Widget    old, new;/i\
  1361. #ifdef __cplusplus\
  1362.     Widget    old, c_new;\
  1363. #else
  1364. ' \
  1365.         -e '/Widget    old, new;/a\
  1366. #endif
  1367. ' \
  1368.     -e 's/Widget new,/Widget c_new,/g' ${LIB}/$file > ${LIB}/${file}.sed
  1369.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1370.   fi
  1371.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1372.     rm -f ${LIB}/$file
  1373.   else
  1374.     # Find any include directives that use "file".
  1375.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1376.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1377.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1378.     done
  1379.   fi
  1380. fi
  1381. # class in Xm/BaseClassI.h
  1382. file=Xm/BaseClassI.h
  1383. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1384.   mkdir ${LIB}/sys 2>/dev/null
  1385.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1386.   chmod +w ${LIB}/$file 2>/dev/null
  1387.   chmod a+r ${LIB}/$file 2>/dev/null
  1388. fi
  1389.  
  1390. if [ -r ${LIB}/$file ]; then
  1391.   if grep __cplusplus ${LIB}/$file >/dev/null 2>/dev/null; then
  1392.     true;
  1393.   else
  1394.     echo Fixing $file, prototype parameter name
  1395.     sed -e 's/ class[)]/ c_class)/g' ${LIB}/$file > ${LIB}/${file}.sed
  1396.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1397.   fi
  1398.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1399.     rm -f ${LIB}/$file
  1400.   else
  1401.     # Find any include directives that use "file".
  1402.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1403.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1404.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1405.     done
  1406.   fi
  1407. fi
  1408.  
  1409. # NeXT 3.2 adds const prefix to some math functions. These conflict
  1410. # with the built-in functions.
  1411. file=ansi/math.h
  1412. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1413.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1414.   chmod +w ${LIB}/$file 2>/dev/null
  1415. fi
  1416. if [ -r ${LIB}/$file ]; then
  1417.   echo Fixing $file
  1418.   sed -e '/^extern.*double.*__const__.*cos(/s/__const__//' \
  1419.       -e '/^extern.*double.*__const__.*sin(/s/__const__//' ${LIB}/$file > ${LIB}/${file}.sed
  1420.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1421.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1422.     rm -f ${LIB}/$file
  1423.   else
  1424.     # Find any include directives that use "file".
  1425.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1426.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1427.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1428.     done
  1429.   fi
  1430. fi
  1431.  
  1432. # NeXT 3.2 uses the word "template" as a parameter for some 
  1433. # functions. GCC reports an invalid use of a reserved key word
  1434. # with the built-in functions. NeXT 3.2 includes the keyword
  1435. # volatile in the prototype for abort(). This conflicts with
  1436. # the built-in definition.
  1437. file=bsd/libc.h
  1438. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1439.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1440.   chmod +w ${LIB}/$file 2>/dev/null
  1441. fi
  1442. if [ -r ${LIB}/$file ]; then
  1443.   echo Fixing $file
  1444.   sed -e '/\(.*template\)/s/template//' \
  1445.       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
  1446.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1447.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1448.     rm -f ${LIB}/$file
  1449.   else
  1450.     # Find any include directives that use "file".
  1451.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1452.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1453.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1454.     done
  1455.   fi
  1456. fi
  1457.  
  1458. # NeXT 3.2 includes the keyword volatile in the abort() and 
  1459. # exit() function prototypes. That conflicts with the 
  1460. # built-in functions.
  1461. file=ansi/stdlib.h
  1462. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1463.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1464.   chmod +w ${LIB}/$file 2>/dev/null
  1465. fi
  1466. if [ -r ${LIB}/$file ]; then
  1467.   echo Fixing $file
  1468.   sed -e '/extern.*volatile.*void.*exit/s/volatile//' \
  1469.       -e '/extern.*volatile.*void.*abort/s/volatile//' ${LIB}/$file > ${LIB}/${file}.sed
  1470.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1471.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1472.     rm -f ${LIB}/$file
  1473.   else
  1474.     # Find any include directives that use "file".
  1475.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1476.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1477.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1478.     done
  1479.   fi
  1480. fi
  1481.  
  1482. # NeXT 2.0 defines 'int wait(union wait*)', which conflicts with Posix.1.
  1483. # Note that version 3 of the NeXT system has wait.h in a different directory,
  1484. # so that this code won't do anything.  But wait.h in version 3 has a
  1485. # conditional, so it doesn't need this fix.  So everything is okay.
  1486. file=sys/wait.h
  1487. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1488.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1489.   chmod +w ${LIB}/$file 2>/dev/null
  1490. fi
  1491.  
  1492. if [ -r ${LIB}/$file ] \
  1493.   && grep 'wait[(]union wait' ${LIB}/$file >/dev/null; then
  1494.   echo Fixing $file, bad wait formal
  1495.   sed -e 's@wait(union wait@wait(void@' ${LIB}/$file > ${LIB}/${file}.sed
  1496.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1497.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1498.     rm -f ${LIB}/$file
  1499.   else
  1500.     # Find any include directives that use "file".
  1501.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1502.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1503.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1504.     done
  1505.   fi
  1506. fi
  1507.  
  1508. # Don't use or define the name va_list in stdio.h.
  1509. # This is for ANSI and also to interoperate properly with gcc's varargs.h.
  1510. file=stdio.h
  1511. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1512.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1513.   chmod +w ${LIB}/$file 2>/dev/null
  1514.   chmod a+r ${LIB}/$file 2>/dev/null
  1515. fi
  1516.  
  1517. if [ -r ${LIB}/$file ]; then
  1518.   echo Fixing $file, use of va_list
  1519.   # Arrange for stdio.h to use stdarg.h to define __gnuc_va_list
  1520.   if egrep "__need___va_list" ${LIB}/$file >/dev/null 2>&1; then
  1521.     touch ${LIB}/${file}.sed
  1522.   else
  1523.     (echo "#define __need___va_list"
  1524.      echo "#include <stdarg.h>") > ${LIB}/${file}.sed
  1525.   fi
  1526.   # Use __gnuc_va_list in arg types in place of va_list.
  1527.   # On 386BSD use __gnuc_va_list instead of _VA_LIST_. We're hoping the
  1528.   # trailing parentheses and semicolon save all other systems from this.
  1529.   # Define __va_list__ (something harmless and unused) instead of va_list.
  1530.   # Don't claim to have defined va_list.
  1531.   sed -e 's@ va_list @ __gnuc_va_list @' \
  1532.       -e 's@ va_list)@ __gnuc_va_list)@' \
  1533.       -e 's@ _BSD_VA_LIST_));@ __gnuc_va_list));@' \
  1534.       -e 's@ _VA_LIST_));@ __gnuc_va_list));@' \
  1535.       -e 's@ va_list@ __va_list__@' \
  1536.       -e 's@\*va_list@*__va_list__@' \
  1537.       -e 's@ __va_list)@ __gnuc_va_list)@' \
  1538.       -e 's@GNUC_VA_LIST@GNUC_Va_LIST@' \
  1539.       -e 's@_NEED___VA_LIST@_NEED___Va_LIST@' \
  1540.       -e 's@VA_LIST@DUMMY_VA_LIST@' \
  1541.       -e 's@_Va_LIST@_VA_LIST@' \
  1542.     ${LIB}/$file >> ${LIB}/${file}.sed
  1543.   
  1544.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1545.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1546.     rm -f ${LIB}/$file
  1547.   else
  1548.     # Find any include directives that use "file".
  1549.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1550.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1551.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1552.     done
  1553.   fi
  1554. fi
  1555.  
  1556. # Cancel out ansi_compat.h on Ultrix.  Replace it with empty file.
  1557. file=ansi_compat.h
  1558. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1559.   if grep -s ULTRIX $file; then
  1560.     echo "/* This file intentionally left blank.  */" > $LIB/$file
  1561.   fi
  1562. fi
  1563.  
  1564. # parameter to atof not const on DECstation Ultrix V4.0 and NEWS-OS 4.2R.
  1565. # also get rid of bogus inline definitions in HP-UX 8.0
  1566. file=math.h
  1567. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1568.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1569.   chmod +w ${LIB}/$file 2>/dev/null
  1570.   chmod a+r ${LIB}/$file 2>/dev/null
  1571. fi
  1572.  
  1573. if [ -r ${LIB}/$file ]; then
  1574.   echo Fixing $file, non-const arg
  1575.   sed -e 's@atof(\([     ]*char[     ]*\*[^)]*\))@atof(const \1)@' \
  1576.       -e 's@inline int abs(int [a-z][a-z]*) {.*}@extern "C" int abs(int);@' \
  1577.       -e 's@inline double abs(double [a-z][a-z]*) {.*}@@' \
  1578.       -e 's@inline int sqr(int [a-z][a-z]*) {.*}@@' \
  1579.       -e 's@inline double sqr(double [a-z][a-z]*) {.*}@@' \
  1580.     ${LIB}/$file > ${LIB}/${file}.sed
  1581.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1582.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1583.     rm -f ${LIB}/$file
  1584.   else
  1585.     # Find any include directives that use "file".
  1586.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1587.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1588.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1589.     done
  1590.   fi
  1591. fi
  1592.  
  1593. # fix bogus recursive stdlib.h in NEWS-OS 4.0C
  1594. file=stdlib.h
  1595. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1596.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1597.   chmod +w ${LIB}/$file 2>/dev/null
  1598.   chmod a+r ${LIB}/$file 2>/dev/null
  1599. fi
  1600.  
  1601. if [ -r ${LIB}/$file ]; then
  1602.   echo Fixing $file, recursive inclusion
  1603.   sed -e '/^#include <stdlib.h>/i\
  1604. #if 0
  1605. ' \
  1606.       -e '/^#include <stdlib.h>/a\
  1607. #endif
  1608. ' \
  1609.     ${LIB}/$file > ${LIB}/${file}.sed
  1610.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1611.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1612.     rm -f ${LIB}/$file
  1613.   else
  1614.     # Find any include directives that use "file".
  1615.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1616.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1617.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1618.     done
  1619.   fi
  1620. fi
  1621.  
  1622. # Avoid nested comments on Ultrix 4.3.
  1623. file=rpc/svc.h
  1624. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1625.   mkdir ${LIB}/rpc 2>/dev/null
  1626.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1627.   chmod +w ${LIB}/$file 2>/dev/null
  1628.   chmod a+r ${LIB}/$file 2>/dev/null
  1629. fi
  1630.  
  1631. if [ -r ${LIB}/$file ]; then
  1632.   echo Fixing $file, nested comment
  1633.   sed -e 's@^\( \*    int protocol;  \)/\*@\1*/ /*@' \
  1634.     ${LIB}/$file > ${LIB}/$file.sed
  1635.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1636.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1637.     rm -f ${LIB}/$file
  1638.   else
  1639.     # Find any include directives that use "file".
  1640.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1641.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1642.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1643.     done
  1644.   fi
  1645. fi
  1646.  
  1647. # This file in RISC/os uses /**/ to concatenate two tokens.
  1648. file=bsd43/bsd43_.h
  1649. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1650.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1651.   chmod +w ${LIB}/$file 2>/dev/null
  1652.   chmod a+r ${LIB}/$file 2>/dev/null
  1653. fi
  1654. if [ -r ${LIB}/$file ]; then
  1655.   sed -e 's|/\*\*/|##|' ${LIB}/$file > ${LIB}/${file}.sed
  1656.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1657.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1658.     rm -f ${LIB}/$file
  1659.   else
  1660.     # Find any include directives that use "file".
  1661.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1662.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1663.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1664.     done
  1665.   fi
  1666. fi
  1667.  
  1668. file=rpc/rpc.h
  1669. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1670.   mkdir ${LIB}/rpc 2>/dev/null
  1671.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1672.   chmod +w ${LIB}/$file 2>/dev/null
  1673.   chmod a+r ${LIB}/$file 2>/dev/null
  1674. fi
  1675.  
  1676. if [ -r ${LIB}/$file ]; then
  1677.   echo Fixing $file, nested comment
  1678.   sed -e 's@^\(/\*.*rpc/auth_des.h>.*\)/\*@\1*/ /*@' \
  1679.     ${LIB}/$file > ${LIB}/$file.sed
  1680.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1681.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1682.     rm -f ${LIB}/$file
  1683.   else
  1684.     # Find any include directives that use "file".
  1685.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1686.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1687.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1688.     done
  1689.   fi
  1690. fi
  1691.  
  1692. # In limits.h, put #ifndefs around things that are supposed to be defined
  1693. # in float.h to avoid redefinition errors if float.h is included first.
  1694. # On HP/UX this patch does not work, because on HP/UX limits.h uses
  1695. # multi line comments and the inserted #endif winds up inside the
  1696. # comment.  Fortunately, HP/UX already uses #ifndefs in limits.h; if
  1697. # we find a #ifndef FLT_MIN we assume that all the required #ifndefs
  1698. # are there, and we do not add them ourselves.
  1699. for file in limits.h sys/limits.h; do
  1700.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1701.     mkdir ${LIB}/sys 2>/dev/null
  1702.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1703.     chmod +w ${LIB}/$file 2>/dev/null
  1704.     chmod a+r ${LIB}/$file 2>/dev/null
  1705.   fi
  1706.  
  1707.   if [ -r ${LIB}/$file ]; then
  1708.     if egrep 'ifndef[     ]+FLT_MIN' ${LIB}/$file >/dev/null; then
  1709.       true
  1710.     else
  1711.       echo Fixing $file
  1712.       sed -e '/[     ]FLT_MIN[     ]/i\
  1713. #ifndef FLT_MIN
  1714. '\
  1715.       -e '/[     ]FLT_MIN[     ]/a\
  1716. #endif
  1717. '\
  1718.       -e '/[     ]FLT_MAX[     ]/i\
  1719. #ifndef FLT_MAX
  1720. '\
  1721.       -e '/[     ]FLT_MAX[     ]/a\
  1722. #endif
  1723. '\
  1724.       -e '/[     ]FLT_DIG[     ]/i\
  1725. #ifndef FLT_DIG
  1726. '\
  1727.       -e '/[     ]FLT_DIG[     ]/a\
  1728. #endif
  1729. '\
  1730.       -e '/[     ]DBL_MIN[     ]/i\
  1731. #ifndef DBL_MIN
  1732. '\
  1733.       -e '/[     ]DBL_MIN[     ]/a\
  1734. #endif
  1735. '\
  1736.       -e '/[     ]DBL_MAX[     ]/i\
  1737. #ifndef DBL_MAX
  1738. '\
  1739.       -e '/[     ]DBL_MAX[     ]/a\
  1740. #endif
  1741. '\
  1742.       -e '/[     ]DBL_DIG[     ]/i\
  1743. #ifndef DBL_DIG
  1744. '\
  1745.       -e '/[     ]DBL_DIG[     ]/a\
  1746. #endif
  1747. '\
  1748.     ${LIB}/$file > ${LIB}/${file}.sed
  1749.       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1750.     fi
  1751.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1752.       echo Deleting ${LIB}/$file\; no fixes were needed.
  1753.       rm -f ${LIB}/$file
  1754.     else
  1755.       # Find any include directives that use "file".
  1756.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1757.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  1758.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1759.       done
  1760.     fi
  1761.   fi
  1762. done
  1763.  
  1764. # In math.h, put #ifndefs around things that might be defined in a gcc
  1765. # specific math-*.h file.
  1766. file=math.h
  1767. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1768.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1769.   chmod +w ${LIB}/$file 2>/dev/null
  1770.   chmod a+r ${LIB}/$file 2>/dev/null
  1771. fi
  1772.  
  1773. if [ -r ${LIB}/$file ]; then
  1774.   echo Fixing $file
  1775.   sed -e '/define[     ]HUGE_VAL[     ]/i\
  1776. #ifndef HUGE_VAL
  1777. '\
  1778.       -e '/define[     ]HUGE_VAL[     ]/a\
  1779. #endif
  1780. '\
  1781.     ${LIB}/$file > ${LIB}/${file}.sed
  1782.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1783.  
  1784.   # In addition, copy the definition of DBL_MAX from float.h
  1785.   # if math.h requires one.  The Lynx math.h requires it.
  1786.   if egrep '#define[     ]*HUGE_VAL[     ]+DBL_MAX' $file >/dev/null 2>&1; then
  1787.     if egrep '#define[     ]+DBL_MAX[     ]+' $file >/dev/null 2>&1; then
  1788.       true;
  1789.     else
  1790.       dbl_max_def=`egrep 'define[     ]+DBL_MAX[     ]+.*' float.h 2>/dev/null`
  1791.       if [ "$dbl_max_def" != "" ]; then
  1792.         dbl_max_def=`echo $dbl_max_def | sed 's/.*define[     ]*DBL_MAX[     ]*//'`
  1793.         sed -e "/define[     ]HUGE_VAL[     ]DBL_MAX/s/DBL_MAX/$dbl_max_def/" \
  1794.           ${LIB}/$file > ${LIB}/${file}.sed
  1795.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1796.       fi
  1797.     fi
  1798.   fi
  1799.  
  1800.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1801.     echo Deleting ${LIB}/$file\; no fixes were needed.
  1802.     rm -f ${LIB}/$file
  1803.   else
  1804.     # Find any include directives that use "file".
  1805.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1806.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1807.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1808.     done
  1809.   fi
  1810. fi
  1811.  
  1812. # Remove erroneous parentheses in sym.h on Alpha OSF/1.
  1813. file=sym.h
  1814. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1815.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1816.   chmod +w ${LIB}/$file 2>/dev/null
  1817.   chmod a+r ${LIB}/$file 2>/dev/null
  1818. fi
  1819.  
  1820. if [ -r ${LIB}/$file ]; then
  1821.   echo Fixing $file
  1822.   sed -e 's/#ifndef(__mips64)/#ifndef __mips64/' \
  1823.     ${LIB}/$file > ${LIB}/${file}.sed
  1824.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1825.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1826.     rm -f ${LIB}/$file
  1827.   else
  1828.     # Find any include directives that use "file".
  1829.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1830.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1831.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1832.     done
  1833.   fi
  1834. fi
  1835.  
  1836. # Correct the return type for strlen in string.h on Lynx.
  1837. # Correct the argument type for ffs in string.h on Alpha OSF/1 V2.0.
  1838. # Add missing const for strdup on OSF/1 V3.0.
  1839. file=string.h
  1840. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1841.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1842.   chmod +w ${LIB}/$file 2>/dev/null
  1843.   chmod a+r ${LIB}/$file 2>/dev/null
  1844. fi
  1845.  
  1846. if [ -r ${LIB}/$file ]; then
  1847.   echo Fixing $file
  1848.   sed -e 's/extern[     ]*int[     ]*strlen();/extern unsigned int strlen();/' \
  1849.       -e 's/extern[     ]*int[     ]*ffs[     ]*(long);/extern int ffs(int);/' \
  1850.       -e 's/strdup(char \*s1);/strdup(const char *s1);/' \
  1851.     ${LIB}/$file > ${LIB}/${file}.sed
  1852.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1853.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1854.     rm -f ${LIB}/$file
  1855.   else
  1856.     # Find any include directives that use "file".
  1857.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1858.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1859.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1860.     done
  1861.   fi
  1862. fi
  1863.  
  1864. # Correct the return type for strlen in strings.h in SunOS 4.
  1865. file=strings.h
  1866. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1867.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1868.   chmod +w ${LIB}/$file 2>/dev/null
  1869.   chmod a+r ${LIB}/$file 2>/dev/null
  1870. fi
  1871.  
  1872. if [ -r ${LIB}/$file ]; then
  1873.   echo Fixing $file
  1874.   sed -e 's/int[     ]*strlen();/__SIZE_TYPE__ strlen();/' \
  1875.     ${LIB}/$file > ${LIB}/${file}.sed
  1876.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1877.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1878.     rm -f ${LIB}/$file
  1879.   else
  1880.     # Find any include directives that use "file".
  1881.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1882.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1883.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1884.     done
  1885.   fi
  1886. fi
  1887.  
  1888. # Delete the '#define void int' line from curses.h on Lynx
  1889. file=curses.h
  1890. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1891.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1892.   chmod +w ${LIB}/$file 2>/dev/null
  1893.   chmod a+r ${LIB}/$file 2>/dev/null
  1894. fi
  1895.  
  1896. if [ -r ${LIB}/$file ]; then
  1897.   echo Fixing $file
  1898.   sed -e '/#[     ]*define[     ][     ]*void[     ]int/d' \
  1899.      ${LIB}/$file > ${LIB}/${file}.sed
  1900.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1901.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1902.     rm -f ${LIB}/$file
  1903.   else
  1904.     # Find any include directives that use "file".
  1905.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1906.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1907.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1908.     done
  1909.   fi
  1910. fi
  1911.  
  1912. # Fix `typedef struct term;' on hppa1.1-hp-hpux9.
  1913. file=curses.h
  1914. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1915.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1916.   chmod +w ${LIB}/$file 2>/dev/null
  1917.   chmod a+r ${LIB}/$file 2>/dev/null
  1918. fi
  1919.  
  1920. if [ -r ${LIB}/$file ]; then
  1921.   echo Fixing $file
  1922.   sed -e 's/^[     ]*typedef[     ][     ]*\(struct[     ][     ]*term[     ]*;[     ]*\)$/\1/' \
  1923.      ${LIB}/$file > ${LIB}/${file}.sed
  1924.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1925.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1926.     rm -f ${LIB}/$file
  1927.   else
  1928.     # Find any include directives that use "file".
  1929.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1930.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1931.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1932.     done
  1933.   fi
  1934. fi
  1935.  
  1936. # For C++, avoid any typedef or macro definition of bool, and use the
  1937. # built in type instead.
  1938. for files in curses.h; do
  1939.   if [ -r $file ] && egrep bool $file >/dev/null 2>&1; then
  1940.     if [ ! -r ${LIB}/$file ]; then
  1941.       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1942.       chmod +w ${LIB}/$file 2>/dev/null
  1943.       chmod a+r ${LIB}/$file 2>/dev/null
  1944.     fi
  1945.  
  1946.     echo Fixing $file
  1947.     sed -e '/^#[     ]*define[     ][     ]*bool[     ][     ]*char[     ]*$/i\
  1948. #ifndef __cplusplus'\
  1949.     -e '/^#[     ]*define[     ][     ]*bool[     ][     ]*char[     ]*$/a\
  1950. #endif'\
  1951.     -e '/^typedef[     ][     ]*char[     ][     ]*bool[        ]*;[     ]*$/i\
  1952. #ifndef __cplusplus'\
  1953.     -e '/^typedef[     ][     ]*char[     ][     ]*bool[        ]*;[     ]*$/a\
  1954. #endif'\
  1955.     ${LIB}/$file > ${LIB}/${file}.sed
  1956.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1957.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1958.       rm -f ${LIB}/$file
  1959.     else
  1960.       # Find any include directives that use "file".
  1961.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1962.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  1963.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1964.       done
  1965.     fi
  1966.   fi
  1967. done
  1968.  
  1969. # Fix incorrect S_IF* definitions on m88k-sysv3.
  1970. file=sys/stat.h
  1971. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1972.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1973.   chmod +w ${LIB}/$file 2>/dev/null
  1974.   chmod a+r ${LIB}/$file 2>/dev/null
  1975. fi
  1976.  
  1977. if [ -r ${LIB}/$file ]; then
  1978.   echo Fixing $file
  1979.   sed -e 's/^\(#define[     ]*S_IS[A-Z]*(m)\)[     ]*(m[     ]*&[     ]*\(S_IF[A-Z][A-Z][A-Z][A-Z]*\)[     ]*)/\1 (((m)\&S_IFMT)==\2)/' \
  1980.       -e 's/^\(#define[     ]*S_IS[A-Z]*(m)\)[     ]*(m[     ]*&[     ]*\(0[0-9]*\)[     ]*)/\1 (((m)\&S_IFMT)==\2)/' \
  1981.     ${LIB}/$file > ${LIB}/${file}.sed
  1982.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  1983.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  1984.     rm -f ${LIB}/$file
  1985.   else
  1986.     # Find any include directives that use "file".
  1987.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  1988.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  1989.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  1990.     done
  1991.   fi
  1992. fi
  1993.  
  1994. # Fix getopt declarations in stdio.h and stdlib.h on Alpha OSF/1 and AIX.
  1995. for file in stdio.h stdlib.h; do
  1996.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  1997.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  1998.     chmod +w ${LIB}/$file 2>/dev/null
  1999.     chmod a+r ${LIB}/$file 2>/dev/null
  2000.   fi
  2001.  
  2002.   if [ -r ${LIB}/$file ]; then
  2003.     echo Fixing $file, getopt declaration
  2004.     sed -e 's/getopt(int, char \*\[\],[ ]*char \*)/getopt(int, char *const[], const char *)/' \
  2005.       ${LIB}/$file > ${LIB}/${file}.sed
  2006.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2007.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2008.       rm -f ${LIB}/$file
  2009.     else
  2010.       # Find any include directives that use "file".
  2011.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2012.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  2013.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2014.       done
  2015.     fi
  2016.   fi
  2017. done
  2018.  
  2019. # Determine if we're on Interactive Unix 2.2 or later, in which case we
  2020. # need to fix some additional files.  This is the same test for ISC that
  2021. # Autoconf uses.
  2022. if test -d /etc/conf/kconfig.d \
  2023.     && grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1; then
  2024.   echo "Fixing ISC __STDC__ goof in several files..."
  2025.   for name in stdio.h math.h ctype.h sys/limits.h sys/fcntl.h sys/dirent.h; do
  2026.     echo $name
  2027.     if test -r ${LIB}/$name; then
  2028.       file=${LIB}/$name
  2029.     else
  2030.       file=${INPUT}/$name
  2031.     fi
  2032.     # On Interactive 2.2, certain traditional Unix definitions
  2033.     # (notably getc and putc in stdio.h) are omitted if __STDC__ is
  2034.     # defined, not just if _POSIX_SOURCE is defined.  This makes it
  2035.     # impossible to compile any nontrivial program except with -posix.
  2036.     sed \
  2037. 's/!defined(__STDC__) && !defined(_POSIX_SOURCE)/!defined(_POSIX_SOURCE)/' \
  2038.         < $file > ${LIB}/$name.
  2039.     mv ${LIB}/$name. ${LIB}/$name
  2040.   done
  2041.   
  2042.   echo "Fixing ISC fmod declaration"
  2043.   # This one's already been fixed for other things.
  2044.   file=${LIB}/math.h
  2045.   sed 's/fmod(double)/fmod(double, double)/' <$file >$file.
  2046.   mv $file. $file
  2047.   
  2048.   echo "Fixing nested comments in ISC <sys/limits.h>"
  2049.   file=sys/limits.h
  2050.   sed '/CHILD_MAX/s,/\* Max, Max,' < ${INPUT}/$file >${LIB}/$file.
  2051.   sed '/OPEN_MAX/s,/\* Max, Max,' < ${LIB}/$file. >${LIB}/$file
  2052. fi
  2053.  
  2054. # These files in Sun OS 4.x use /**/ to concatenate tokens.
  2055. for file in sparc/asm_linkage.h sun3/asm_linkage.h sun3x/asm_linkage.h    \
  2056.     sun4/asm_linkage.h sun4c/asm_linkage.h sun4m/asm_linkage.h    \
  2057.     sun4c/debug/asm_linkage.h sun4m/debug/asm_linkage.h;
  2058. do
  2059.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2060.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2061.     chmod +w ${LIB}/$file 2>/dev/null
  2062.     chmod a+r ${LIB}/$file 2>/dev/null
  2063.   fi
  2064.  
  2065.   if [ -r ${LIB}/$file ]; then
  2066.     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
  2067.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2068.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2069.       rm -f ${LIB}/$file
  2070.     else
  2071.       # Find any include directives that use "file".
  2072.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2073.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  2074.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2075.       done
  2076.     fi
  2077.   fi
  2078. done
  2079.  
  2080. # These files in ARM/RISCiX use /**/ to concatenate tokens.
  2081. for file in arm/as_support.h arm/mc_type.h arm/xcb.h dev/chardefmac.h \
  2082.     dev/ps_irq.h dev/screen.h dev/scsi.h sys/tty.h Xm.acorn/XmP.h
  2083. do
  2084.   if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2085.     cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2086.     chmod +w ${LIB}/$file 2>/dev/null
  2087.     chmod a+r ${LIB}/$file 2>/dev/null
  2088.   fi
  2089.  
  2090.   if [ -r ${LIB}/$file ]; then
  2091.     sed -e 's|/\*\*/|##|g' ${LIB}/$file > ${LIB}/${file}.sed
  2092.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2093.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2094.       rm -f ${LIB}/$file
  2095.   else
  2096.     # Find any include directives that use "file".
  2097.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2098.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2099.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2100.     done
  2101.     fi
  2102.   fi
  2103. done
  2104.  
  2105. # math.h on SunOS 4 puts the declaration of matherr before the definition
  2106. # of struct exception, so the prototype (added by fixproto) causes havoc.
  2107. file=math.h
  2108. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2109.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2110.   chmod +w ${LIB}/$file 2>/dev/null
  2111.   chmod a+r ${LIB}/$file 2>/dev/null
  2112. fi
  2113.  
  2114. if [ -r ${LIB}/$file ]; then
  2115.   echo Fixing $file, matherr declaration
  2116.   sed -e '/^struct exception/,$b' \
  2117.       -e '/matherr/i\
  2118. struct exception;
  2119. '\
  2120.     ${LIB}/$file > ${LIB}/${file}.sed
  2121.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2122.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2123.     rm -f ${LIB}/$file
  2124.   else
  2125.     # Find any include directives that use "file".
  2126.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2127.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2128.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2129.     done
  2130.   fi
  2131. fi
  2132.  
  2133. # assert.h on HP/UX is not C++ ready, even though NO_IMPLICIT_EXTERN_C
  2134. # is defined on HP/UX.
  2135. file=assert.h
  2136. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2137.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2138.   chmod +w ${LIB}/$file 2>/dev/null
  2139.   chmod a+r ${LIB}/$file 2>/dev/null
  2140. fi
  2141.  
  2142. if [ -r ${LIB}/$file ]; then
  2143.   if egrep '"C"' ${LIB}/$file >/dev/null 2>&1 \
  2144.      || egrep '__BEGIN_DECLS' ${LIB}/$file >/dev/null 2>&1; then
  2145.     true
  2146.   else
  2147.     echo Fixing $file
  2148.     echo '#ifdef __cplusplus
  2149. extern "C" {
  2150. #endif' > ${LIB}/${file}.sed
  2151.     cat ${LIB}/${file} >> ${LIB}/${file}.sed
  2152.     echo '#ifdef __cplusplus
  2153. }
  2154. #endif' >> ${LIB}/${file}.sed 
  2155.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2156.     if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2157.       rm -f ${LIB}/$file
  2158.     else
  2159.       # Find any include directives that use "file".
  2160.       for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2161.         dir=`echo $file | sed -e s'|/[^/]*$||'`
  2162.         required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2163.       done
  2164.     fi
  2165.   fi
  2166. fi
  2167.  
  2168. # check for broken assert.h that needs stdio.h or stdlib.h
  2169. file=assert.h
  2170. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2171.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2172.   chmod +w ${LIB}/$file 2>/dev/null
  2173.   chmod a+r ${LIB}/$file 2>/dev/null
  2174. fi
  2175.  
  2176. if [ -r ${LIB}/$file ]; then
  2177.   if grep 'stderr' ${LIB}/$file >/dev/null 2>/dev/null; then
  2178.     if grep 'include.*stdio.h' ${LIB}/$file >/dev/null 2>/dev/null; then
  2179.       true
  2180.     else
  2181.       echo "Fixing $file (needs stdio.h)"
  2182.       echo '#ifdef __cplusplus
  2183. #include <stdio.h>
  2184. #endif' >>${LIB}/$file
  2185.     fi
  2186.   fi
  2187.   if grep 'exit *(' ${LIB}/$file >/dev/null 2>/dev/null || 
  2188.      grep 'abort *(' ${LIB}/$file >/dev/null 2>/dev/null; then
  2189.     if grep 'include.*stdlib.h' ${LIB}/$file >/dev/null 2>/dev/null; then
  2190.       true
  2191.     else
  2192.       echo "Fixing $file (needs stdlib.h)"
  2193.       echo '#ifdef __cplusplus
  2194. #include <stdlib.h>
  2195. #endif' >>${LIB}/$file
  2196.     fi
  2197.   fi
  2198.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2199.     rm -f ${LIB}/$file
  2200.   else
  2201.     # Find any include directives that use "file".
  2202.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2203.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2204.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2205.     done
  2206.   fi
  2207. fi
  2208.  
  2209. # Fix return value of sbrk in unistd.h on Alpha OSF/1 V2.0
  2210. file=unistd.h
  2211. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2212.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2213.   chmod +w ${LIB}/$file 2>/dev/null
  2214.   chmod a+r ${LIB}/$file 2>/dev/null
  2215. fi
  2216.  
  2217. if [ -r ${LIB}/$file ]; then
  2218.   echo Fixing $file, sbrk declaration
  2219.   sed -e 's/char\([     ]*\*[     ]*sbrk[     ]*(\)/void\1/' \
  2220.     ${LIB}/$file > ${LIB}/${file}.sed
  2221.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2222.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2223.     rm -f ${LIB}/$file
  2224.   else
  2225.     # Find any include directives that use "file".
  2226.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2227.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2228.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2229.     done
  2230.   fi
  2231. fi
  2232.  
  2233. # This file on SunOS 4 has a very large macro.  When the sed loop
  2234. # tries pull it in, it overflows the pattern space size of the SunOS
  2235. # sed (GNU sed does not have this problem).  Since the file does not
  2236. # require fixing, we remove it from the fixed directory.
  2237. file=sundev/ipi_error.h
  2238. if [ -r ${LIB}/$file ]; then
  2239.   echo "Removing incorrect fix to SunOS <sundev/ipi_error.h>"
  2240.   rm -f ${LIB}/$file
  2241. fi
  2242.  
  2243. # Put cpp wrappers around these include files to avoid redeclaration
  2244. # errors during multiple inclusion on m88k-tektronix-sysv3.
  2245. for file in time.h sys/time.h ; do
  2246.   if egrep '#ifndef' $file >/dev/null 2>&1; then
  2247.     true
  2248.   else
  2249.     if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2250.       cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2251.       chmod +w ${LIB}/$file 2>/dev/null
  2252.     fi
  2253.     if [ -r ${LIB}/$file ]; then
  2254.       echo Fixing $file, to protect against multiple inclusion.
  2255.       cpp_wrapper=`echo $file | sed -e 's,\.,_,g' -e 's,/,_,g'`
  2256.       (echo "#ifndef __GCC_GOT_${cpp_wrapper}_"
  2257.       echo "#define __GCC_GOT_${cpp_wrapper}_"
  2258.       cat ${LIB}/${file}
  2259.       echo '#endif /* !_GCC_GOT_'${cpp_wrapper}_' */')  > ${LIB}/${file}.new
  2260.       rm -f ${LIB}/$file; mv ${LIB}/${file}.new ${LIB}/$file
  2261.     fi
  2262.   fi
  2263. done
  2264.  
  2265. # Fix fcntl prototype in fcntl.h on LynxOS.
  2266. file=fcntl.h
  2267. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2268.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2269.   chmod +w ${LIB}/$file 2>/dev/null
  2270.   chmod a+r ${LIB}/$file 2>/dev/null
  2271. fi
  2272.  
  2273. if [ -r ${LIB}/$file ]; then
  2274.   echo Fixing $file, fcntl declaration
  2275.   sed -e 's/\(fcntl.*(int, int, \)int)/\1...)/' \
  2276.     ${LIB}/$file > ${LIB}/${file}.sed
  2277.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2278.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2279.     rm -f ${LIB}/$file
  2280.   else
  2281.     # Find any include directives that use "file".
  2282.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2283.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2284.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2285.     done
  2286.   fi
  2287. fi
  2288.  
  2289. # Fix definitions of macros used by va-i960.h in VxWorks header file.
  2290. file=arch/i960/archI960.h
  2291. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2292.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2293.   chmod +w ${LIB}/$file 2>/dev/null
  2294.   chmod a+r ${LIB}/$file 2>/dev/null
  2295. fi
  2296.  
  2297. if [ -r ${LIB}/$file ]; then
  2298.   echo Fixing $file
  2299.   sed -e 's/__vsiz/__vxvsiz/' -e 's/__vali/__vxvali/' \
  2300.       -e s'/__vpad/__vxvpad/' -e 's/__alignof__/__vxalignof__/' \
  2301.     ${LIB}/$file > ${LIB}/${file}.sed
  2302.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2303.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2304.     rm -f ${LIB}/$file
  2305.   else
  2306.     # Find any include directives that use "file".
  2307.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2308.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2309.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2310.     done
  2311.   fi
  2312. fi
  2313.  
  2314. # Make VxWorks header which is almost gcc ready fully gcc ready.
  2315. file=types/vxTypesBase.h
  2316. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2317.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2318.   chmod +w ${LIB}/$file 2>/dev/null
  2319.   chmod a+r ${LIB}/$file 2>/dev/null
  2320. fi
  2321.  
  2322. if [ -r ${LIB}/$file ]; then
  2323.   echo Fixing $file
  2324.   sed -e 's/#ifdef __GNUC_TYPEOF_FEATURE_BROKEN_USE_DEFAULT_UNTIL_FIXED__/#if 1/' \
  2325.       -e '/[     ]size_t/i\
  2326. #ifndef _GCC_SIZE_T\
  2327. #define _GCC_SIZE_T
  2328. ' \
  2329.       -e '/[     ]size_t/a\
  2330. #endif
  2331. ' \
  2332.       -e '/[     ]ptrdiff_t/i\
  2333. #ifndef _GCC_PTRDIFF_T\
  2334. #define _GCC_PTRDIFF_T
  2335. ' \
  2336.       -e '/[     ]ptrdiff_t/a\
  2337. #endif
  2338. ' \
  2339.       -e '/[     ]wchar_t/i\
  2340. #ifndef _GCC_WCHAR_T\
  2341. #define _GCC_WCHAR_T
  2342. ' \
  2343.       -e '/[     ]wchar_t/a\
  2344. #endif
  2345. ' \
  2346.     ${LIB}/$file > ${LIB}/${file}.sed
  2347.   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2348.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2349.     rm -f ${LIB}/$file
  2350.   else
  2351.     # Find any include directives that use "file".
  2352.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2353.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2354.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2355.     done
  2356.   fi
  2357. fi
  2358.  
  2359. # Fix VxWorks <sys/stat.h> to not require including <vxWorks.h>.
  2360. file=sys/stat.h
  2361. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2362.   mkdir ${LIB}/sys 2>/dev/null
  2363.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2364.   chmod +w ${LIB}/$file 2>/dev/null
  2365.   chmod a+r ${LIB}/$file 2>/dev/null
  2366. fi
  2367.  
  2368. if [ -r ${LIB}/$file ]; then
  2369.   if egrep '#include' ${LIB}/$file >/dev/null 2>&1; then
  2370.     :
  2371.   else
  2372.     if egrep 'ULONG' ${LIB}/$file >/dev/null 2>&1 \
  2373.        && [ -r types/vxTypesOld.h ]; then
  2374.       echo Fixing $file
  2375.       sed -e '/#define[     ][     ]*__INCstath/a\
  2376. #include <types/vxTypesOld.h>
  2377. ' \
  2378.     ${LIB}/$file > ${LIB}/${file}.sed
  2379.       rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2380.     fi
  2381.   fi
  2382.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2383.     rm -f ${LIB}/$file
  2384.   else
  2385.     # Find any include directives that use "file".
  2386.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2387.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2388.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2389.     done
  2390.   fi
  2391. fi
  2392.  
  2393. # Fix VxWorks <time.h> to not require including <vxTypes.h>.
  2394. file=time.h
  2395. if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
  2396.   mkdir ${LIB}/sys 2>/dev/null
  2397.   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
  2398.   chmod +w ${LIB}/$file 2>/dev/null
  2399.   chmod a+r ${LIB}/$file 2>/dev/null
  2400. fi
  2401.  
  2402. if [ -r ${LIB}/$file ]; then
  2403.   if egrep 'uint_t[     ][     ]*_clocks_per_sec' ${LIB}/$file >/dev/null 2>&1; then
  2404.     echo Fixing $file
  2405.     sed -e 's/uint_t/unsigned int/' ${LIB}/$file > ${LIB}/${file}.sed
  2406.     rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
  2407.   fi
  2408.   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
  2409.     rm -f ${LIB}/$file
  2410.   else
  2411.     # Find any include directives that use "file".
  2412.     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
  2413.       dir=`echo $file | sed -e s'|/[^/]*$||'`
  2414.       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
  2415.     done
  2416.   fi
  2417. fi
  2418.     
  2419.  
  2420. # This loop does not appear to do anything, because it uses file
  2421. # rather than $file when setting target.  It also appears to be
  2422. # unnecessary, since the main loop processes symbolic links.
  2423. #if $LINKS; then
  2424. #  echo 'Making internal symbolic non-directory links'
  2425. #  cd ${INPUT}
  2426. #  files=`find . -type l -print`
  2427. #  for file in $files; do
  2428. #    dest=`ls -ld $file | sed -n 's/.*-> //p'`
  2429. #    if expr "$dest" : '[^/].*' > /dev/null; then    
  2430. #      target=${LIB}/`echo file | sed "s|[^/]*\$|$dest|"`
  2431. #      if [ -f $target ]; then
  2432. #        ln -s $dest ${LIB}/$file >/dev/null 2>&1
  2433. #      fi
  2434. #    fi
  2435. #  done
  2436. #fi
  2437.  
  2438. # Make sure that any include files referenced using double quotes
  2439. # exist in the fixed directory.  This comes last since otherwise
  2440. # we might end up deleting some of these files "because they don't
  2441. # need any change."
  2442. set x $required
  2443. shift
  2444. while [ $# != 0 ]; do
  2445.   newreq=
  2446.   while [ $# != 0 ]; do
  2447.     # $1 is the directory to copy from, $2 is the unfixed file,
  2448.     # $3 is the fixed file name.
  2449.     cd ${INPUT}
  2450.     cd $1
  2451.     if [ -r $2 ] && [ ! -r $3 ]; then
  2452.       cp $2 $3 >/dev/null 2>&1 || echo "Can't copy $2"
  2453.       chmod +w $3 2>/dev/null
  2454.       chmod a+r $3 2>/dev/null
  2455.       echo Copied $2
  2456.       for include in `egrep '^[     ]*#[     ]*include[     ]*"[^/]' $3 | sed -e 's/^[     ]*#[     ]*include[     ]*"\([^"]*\)".*$/\1/'`; do
  2457.     dir=`echo $2 | sed -e s'|/[^/]*$||'`
  2458.     dir2=`echo $3 | sed -e s'|/[^/]*$||'`
  2459.     newreq="$newreq $1 $dir/$include $dir2/$include"
  2460.       done
  2461.     fi
  2462.     shift; shift; shift
  2463.   done
  2464.   set x $newreq
  2465.   shift
  2466. done
  2467.  
  2468. echo 'Cleaning up DONE files.'
  2469. cd $LIB
  2470. find . -name DONE -exec rm -f '{}' ';'
  2471.  
  2472. echo 'Removing unneeded directories:'
  2473. cd $LIB
  2474. files=`find . -type d -print | sort -r`
  2475. for file in $files; do
  2476.   rmdir $LIB/$file > /dev/null 2>&1
  2477. done
  2478.  
  2479. exit 0
  2480.